﻿using System;

class GivenIntegerAndBit
{
    static void Main()
    {
        //Exercise 11.
        //Write an expression that extracts from a given integer i the value of a given bit number b. Example: i=5; b=2 -> value=1.

        Console.Write("Enter an integer: ");
        int i = int.Parse(Console.ReadLine());
        Console.Write("Enter bit position: ");
        int b = int.Parse(Console.ReadLine());
        string i2 = Convert.ToString(i, 2).PadLeft(32,'0');
        Console.WriteLine(i2);
        int mask = 1 << b;
        int result = i & mask;
        int finalresult = result >> b;
        Console.WriteLine("In integer {0} the value of bit position {1} is:  {2} .", i, b, finalresult);
    }
}

